/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */
package l1j.server.server.serverpackets;

import java.util.logging.Logger;

import l1j.server.server.Opcodes;
import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.model.Instance.L1PcInstance;

public class S_CharInvVisualUpdate extends ServerBasePacket {
	private static final String S_CHAR_INV_VISUAL_UPDATE = "[S] S_CharInvVisualUpdate";
	private static Logger _log = Logger.getLogger(S_CharInvVisualUpdate.class
			.getName());

	public S_CharInvVisualUpdate(L1PcInstance pc, int objid) {

		L1ItemInstance temp = pc.getInventory().getItem(objid);

		if (temp.getItem().getType2() == 0) {
			writeC(Opcodes.S_OPCODE_CHARINVVISUALUPDATE);
			writeD(temp.getId());

			if (temp.getCount() > 1) {
				writeS(temp.getItem().getName() + " (" + temp.getCount() + ")");
			} else {
				writeS(temp.getItem().getName());
			}
		}

		if (temp.getItem().getType2() == 1) {
			writeC(Opcodes.S_OPCODE_CHARINVVISUALUPDATE);
			writeD(temp.getId());

			if (!temp.isEquipped()) {
				if (!temp.isIdentified()) {
					writeS(temp.getItem().getName() + " (" + "$9" + ")");
				} else {
					if (temp.getEnchantLevel() > 0) {
						writeS("+" + temp.getEnchantLevel() + " "
								+ temp.getItem().getName() + " (" + "$9" + ")");
					} else {
						writeS(temp.getItem().getName() + " (" + "$9" + ")");
					}
				}
			} else if (temp.isEquipped()) {
				if (!temp.isIdentified()) {
					writeS(temp.getItem().getName());
				} else {
					if (temp.getEnchantLevel() > 0) {
						writeS("+" + temp.getEnchantLevel() + " "
								+ temp.getItem().getName());
					} else {
						writeS(temp.getItem().getName());
					}
				}
			}
		}

		if (temp.getItem().getType2() == 2) {
			writeC(Opcodes.S_OPCODE_CHARINVVISUALUPDATE);
			writeD(temp.getId());

			if (!temp.isEquipped()) {
				if (!temp.isIdentified()) {
					writeS(temp.getItem().getName() + " (" + "$117" + ")");
				} else {
					if (temp.getEnchantLevel() > 0) {
						writeS("+" + temp.getEnchantLevel() + " "
								+ temp.getItem().getName() + " (" + "$117"
								+ ")");
					} else {
						writeS(temp.getItem().getName() + " (" + "$117" + ")");
					}
				}
			} else if (temp.isEquipped()) {
				if (!temp.isIdentified()) {
					writeS(temp.getItem().getName());
				} else {
					if (temp.getEnchantLevel() > 0) {
						writeS("+" + temp.getEnchantLevel() + " "
								+ temp.getItem().getName());
					} else {
						writeS(temp.getItem().getName());
					}
				}
			}
		}
	}

	@Override
	public byte[] getContent() {
		return getBytes();
	}

	public String getType() {
		return S_CHAR_INV_VISUAL_UPDATE;
	}
}
